﻿#region Copyright and License
/*==============================================================================
 *  Copyright (c) www.51mvc.com Corporation.  All rights reserved.
 * ===============================================================================
 * This code and information is provided "as is" without warranty of any kind,
 * either expressed or implied, including but not limited to the implied warranties
 * of merchantability and fitness for a particular purpose.
 * ===============================================================================
 * Licensed under the GNU General Public License (GPL) v2
 * http://www.51mvc.com/
 * Create By 小鱼(Leven)  - http://leven.com.cn
 * ==============================================================================*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace JXT.PrimaryKey.Batman.Container
{
    /// <summary>
    /// 容器接口
    /// </summary>
    public interface IContainer : IDisposable {
        /// <summary>
        /// 容器名称
        /// </summary>
        string Name { get; }

        /// <summary>
        /// 初始化方法
        /// </summary>
        void Initialize();

        /// <summary>
        /// 加载类型，类型为接口
        /// </summary>
        /// <code>
        /// <![CDATA[
        /// IContainer container = new xxxContainer();
        /// IUserService service container.Resolve<IUserSerivce>();
        /// ]]>
        /// </code>
        /// <typeparam name="T">数据类型</typeparam>
        /// <param name="name">配置名称</param>
        /// <returns>从容器中取得的对象</returns>
        T Resolve<T>(string name = null);

        /// <summary>
        /// 卸载容器
        /// </summary>
        void TearDown();

        #region Events

        /// <summary>
        /// 初始化开始事件
        /// </summary>
        event EventHandler<ContainerEventsArgs> Initializing;

        /// <summary>
        /// 初始化结束事件
        /// </summary>
        event EventHandler<ContainerEventsArgs> Initialized;

        /// <summary>
        /// 卸载开始事件
        /// </summary>
        event EventHandler<ContainerEventsArgs> TearDowning;

        /// <summary>
        /// 卸载结束事件
        /// </summary>
        event EventHandler<ContainerEventsArgs> TearDowned;

        /// <summary>
        /// 加载错误事件
        /// </summary>
        event EventHandler<ContainerFailedEventsArgs> ResolveFailed;

        #endregion
    }
}
